class Solution {
    int count;
    bool check[16];
public:
    int countArrangement(int n) {
        dfs(1, n);
        return count;
    }

    void dfs(int pos, int n)
    {
        if (pos == n + 1)
        {
            count++;
            return;
        }

        for (int i = 1; i < n + 1; i++)
        {
            if (!check[i] && ((pos % i == 0) || (i % pos == 0)))
            {
                check[i] = true;
                dfs(pos + 1, n);
                check[i] = false;
            }
        }


    }
};